<% edit_perm = has_permission?("LoadBalancer:edit", @lb)
delete_perm = has_permission?("LoadBalancer:delete", @lb) %>

<% if edit_perm || delete_perm %>
  <div class="p-6">
    <div class="md:flex md:items-center md:justify-between pb-2 lg:pb-4">
      <div class="min-w-0 flex-1">
        <h3 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-2xl sm:tracking-tight">
          Danger Zone
        </h3>
      </div>
    </div>
    <div class="overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5 bg-white divide-y divide-gray-200">
      <% if edit_perm %>
        <div class="px-4 py-5 sm:p-6">
          <% form(action: "#{path(@lb)}/rename", method: :post) do %>
            <%== part("components/rename_object_input", object: @lb, type: "load balancer", text: "Renaming a load balancer changes the DNS name used, so configuration changes may be required if the load balancer is renamed. You will also need to renew the SSL certificate in the virtual machines attached to this load balancer.") %>
          <% end %>
        </div>
        <div class="px-4 py-5 sm:p-6">
          <div class="sm:flex sm:items-center sm:justify-between">
            <div>
              <h3 class="text-base font-semibold leading-6 text-gray-900">SSL Certificate</h3>
              <div class="mt-2 text-sm text-gray-500">
                <p>Ubicloud automatically provides a free SSL certificate for your load balancer. To enable it, toggle
                  the switch.</p>
                <p>Learn more about Ubicloud SSL certificates in the
                  <a
                    href="https://www.ubicloud.com/docs/networking/load-balancer#ssl-certificates"
                    class="text-orange-600 hover:text-orange-700"
                    target="_blank"
                  >documentation</a>.</p>
              </div>
            </div>
            <div class="mt-5 sm:ml-6 sm:mt-0 sm:flex sm:flex-shrink-0 sm:items-center">
              <%== part("components/form/toggle_form", name: "cert_enabled", action: "#{path(@lb)}/toggle-ssl-certificate", active: @lb.cert_enabled) %>
            </div>
          </div>
        </div>
      <% end %>
      <% if delete_perm %>
        <div class="px-4 py-5 sm:p-6">
          <div class="sm:flex sm:items-center sm:justify-between">
            <div>
              <h3 class="text-base font-semibold leading-6 text-gray-900">Delete load balancer</h3>
              <div class="mt-2 text-sm text-gray-500">
                <p>This action will permanently delete this load balancer. Deleted load balancer cannot be recovered.
                  Use it carefully.</p>
              </div>
            </div>
            <div class="mt-5 sm:ml-6 sm:mt-0 sm:flex sm:flex-shrink-0 sm:items-center">
              <%== part("components/delete_button", url: path(@lb), confirmation: @lb.name, redirect: "#{@project.path}/load-balancer") %>
            </div>
          </div>
        </div>
      <% end %>
    </div>
  </div>
<% end %>
